package com.admxj.mybatis.demo;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.jdbc.JdbcTransaction;
import org.junit.Before;
import org.junit.Test;

import java.io.Reader;
import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author jin.xiang
 * @version Id: MybatisDemo, v 0.1 2020/6/1 3:49 下午 jin.xiang Exp $
 */
public class MybatisDemo {

  protected SqlSessionFactory sessionFactory;
  protected static Configuration configuration;

  protected Connection connection;
  protected JdbcTransaction jdbcTransaction;

  protected static final String url = "jdbc:mysql://127.0.0.1:3306/test";
  protected static final String user = "root";
  protected static final String password = "123456";


  @Before
  public void setUp() throws Exception {
    try (Reader reader = Resources.getResourceAsReader("com/admxj/mybatis/demo/mybatis-config.xml")) {
      sessionFactory = new SqlSessionFactoryBuilder().build(reader);

      configuration = sessionFactory.getConfiguration();
      connection = DriverManager.getConnection(url, user, password);
      jdbcTransaction = new JdbcTransaction(connection);

    }
  }


  @Test
  public void test(){
    SqlSession sqlSession = sessionFactory.openSession();



  }

}
